package cn.edu.zafu.bigdata.zqt.Error;

public class out {
    public static void main(String[] args) {
        try {
            int[] arr = {1, 2, 3};
            int index = 3;
            int element = getElement(arr, index);
            System.out.println(element);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println(e.getMessage());
        } // 添加闭合括号
    }

    public static int getElement(int[] arr, int index) {
        if (index < 0 || index >= arr.length) {
            throw new ArrayIndexOutOfBoundsException("下标越界");
        }
        return arr[index];
    }
}
